package com.tvunetworks.device.extra.constants;

import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import lombok.Getter;

/**
 * @author Etan Yang
 * @create: 2021/11/19 15:48
 */

public interface ResultConstant {
    /**
     * user exception
     */
    interface User {
        Result CALL_CC_USER_SERVICE_EXCEPTION = ResultUtil.error("80801000", "Call TVUCC User Service exception.");
        Result CALL_USER_GROUP_SERVICE_EXCEPTION = ResultUtil.error("80801001", "Call User Group Service exception.");
        Result USER_NOT_EXIST = ResultUtil.error("80801002", "User not Exist.");
        Result ADD_EXT_TO_USER_FAILED = ResultUtil.error("80801003", "Add ext to user failed.");
        Result USER_ID_CAN_NOT_EMPTY = ResultUtil.error("80801004", "UserId can not be empty");
    }

    /**
     * device exception
     */
    interface Device {
        Result DEVICE_IS_NOT_EXIST = ResultUtil.error("80802000", "Device is not exist.");
        Result DEVICE_IS_LIVING_CAN_NOT_DELETE = ResultUtil.error("80802001", "Device is living,can not delete.");
        Result CHANNEL_USE_THIS_DEVICE = ResultUtil.error("80802002", "Device is used in channel service,Are you sure delete.");
        Result DEVICE_IS_LIVING = ResultUtil.error("80802003", "Device is living,Can't broadcast live to other devices.");
        Result DEVICE_IS_OFFLINE = ResultUtil.error("80802004", "Device is offline.");
        Result DEVICE_LIVING_FAIL = ResultUtil.error("80802005", "Token Pairing failed");
        Result DEVICE_PAIR_FAIL = ResultUtil.error("80802006", "GCS Pairing failed");
        Result GET_DEVICE_FIRST = ResultUtil.error("80802007", "get firstObjectId failed");
        Result GET_DEVICE_SECOND = ResultUtil.error("80802008", "get secondObjectId failed");
        Result DEVICE_LIVE_ERROR = ResultUtil.error("80802009", "the device startLive failed");

    }

    /**
     * token exception
     */
    interface Token {
        Result CREATE_TOKEN_FAILED = ResultUtil.error("80803000", "Create Token failed.");
        Result TOKEN_PAIR_CONFIRM_FAILED = ResultUtil.error("80803001", "Token Pair Confirm failed.");

    }

    /**
     * region相关的exception
     */
    interface Region {
        Result GOT_DEFAULT_REGION_FAILED = ResultUtil.error("80804000", "There are some errors happened when trying to get default region.");
    }

    /**
     * grid error
     */
    @Getter
    enum GIRD {
        /**
         * grid error msg
         */
        ERROR_1("80805000","2147483648","r unknown error"),
        ERROR_2("80805001","2147483649","peer not found"),
        ERROR_3("80805002","2147483650","live with other"),
        ERROR_4("80805003","2147483651","grid status error"),
        SHARE_LIMIT("82000406","82000406","The specified streaming limit has been reached"),
        ERROR_5("80805005","80805005","pair R not contain global grid feature"),
        ERROR_6("80805006","80805006","r code success but device status not success")
        ;
        private String code;
        private String thirdCode;
        private String message;
        GIRD(String code,String thirdCode,String message){
            this.code=code;
            this.message=message;
            this.thirdCode=thirdCode;
        }

        /**
         * build error
         * @param command command
         * @param errorCode errorCode
         */
        public static void buildError(Result<String> command, Object errorCode) {
            GIRD error = GIRD.ERROR_1;
            for (GIRD value : GIRD.values()) {
                if(value.thirdCode.equals(errorCode)){
                    error=value;
                    break;
                }
            }
            command.setErrorCode(error.code);
            command.setErrorInfo(error.message);
        }

        /**
         * grid error
         * @param gird grid
         * @return result
         */
        public static Result getError(GIRD gird){
            return ResultUtil.error(gird.code, gird.message);
        }
    }

}
